package com.cction.comm;

import android.content.Context;

import com.yanyusong.y_divideritemdecoration.Y_Divider;
import com.yanyusong.y_divideritemdecoration.Y_DividerBuilder;
import com.yanyusong.y_divideritemdecoration.Y_DividerItemDecoration;

public class GridDividerItemDecoration extends Y_DividerItemDecoration {

    private final int COLOR = 0xffEDEDED;
    private final int WIDTHDP = 1;
    private final int STARTPADDINGDP = 0;
    private final int ENDPADDINGDP = 0;

    public GridDividerItemDecoration(Context context) {
        super(context);
    }

    @Override
    public Y_Divider getDivider(int itemPosition) {
        Y_Divider divider = null;
        switch (itemPosition % 3) {
            case 0:
                if (itemPosition / 3 >= 1) {
                    divider = new Y_DividerBuilder()
                            .setLeftSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .setBottomSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .setRightSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .create();
                } else {
                    divider = new Y_DividerBuilder()
                            .setLeftSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .setBottomSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .setRightSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .setTopSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .create();
                }
                break;
            case 1:
                if (itemPosition / 3 >= 1) {
                    divider = new Y_DividerBuilder()
                            .setBottomSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .create();
                } else {
                    divider = new Y_DividerBuilder()
                            .setTopSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .setBottomSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .create();
                }

                break;
            case 2:
                if (itemPosition / 3 >= 1) {
                    divider = new Y_DividerBuilder()
                            .setLeftSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .setBottomSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .setRightSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .create();
                } else {
                    divider = new Y_DividerBuilder()
                            .setLeftSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .setBottomSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .setRightSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .setTopSideLine(true, COLOR, WIDTHDP, STARTPADDINGDP, ENDPADDINGDP)
                            .create();
                }
                break;
        }
        return divider;
    }
}
